import config from '@/config/config.js';
import axios from "axios";

const warehouseLocationRequest = {
    loadWarehouseLocationList(searchWarehouseLocation,pageNum,limit,callback){
        let url = config.warehouseBaseUrl + "/warehouseLocation/list?pageNum=" + pageNum + "&limit=" + limit + "&warehouseAreaId=" + searchWarehouseLocation.warehouseAreaId
        if (searchWarehouseLocation.warehouseLocationId){
            url += "&warehouseLocationId=" + searchWarehouseLocation.warehouseLocationId
        }
        if (searchWarehouseLocation.warehouseLocationName){
            url += "&warehouseLocationName=" + searchWarehouseLocation.warehouseLocationName
        }
        if (searchWarehouseLocation.warehouseLocationNumberX){
            url += "&warehouseLocationNumberX=" +searchWarehouseLocation.warehouseLocationNumberX
        }
        if (searchWarehouseLocation.warehouseLocationNumberY){
            url += "&warehouseLocationNumberY=" +searchWarehouseLocation.warehouseLocationNumberY
        }
        if (searchWarehouseLocation.warehouseLocationNumberZ){
            url += "&warehouseLocationNumberZ=" +searchWarehouseLocation.warehouseLocationNumberZ
        }
        axios.get(url,{
            headers:{
                token:localStorage.getItem("token")
            }
        }).then(res=>{
            callback(res.data.data)
        })
    },
    loadSearchInfo(warehouseLocationId,warehouseAreaId,callback){
        let url = config.warehouseBaseUrl + "/warehouseLocation/updateInfo?warehouseLocationId=" + warehouseLocationId + "&warehouseAreaId=" + warehouseAreaId
        axios.get(url,{
            headers:{
                token:localStorage.getItem("token")
            }
        }).then(res=>{
            callback(res.data)
        })
    },
    deleteWarehouseLocation(warehouseLocationId,warehouseAreaId,callback){
        let url = config.warehouseBaseUrl + "/warehouseLocation/delete?warehouseLocationId=" + warehouseLocationId + "&warehouseAreaId=" + warehouseAreaId
        axios.delete(url,{
            headers:{
                token:localStorage.getItem("token")
            }
        }).then(res=>{
            callback(res.data)
        })
    },
    updateWarehouseLocation(updateWarehouseLocation,callback){
        let url = config.warehouseBaseUrl +"/warehouseLocation/update"
        axios.put(url,updateWarehouseLocation,{
            headers:{
                token:localStorage.getItem("token")
            }
        }).then(res=>{
            callback(res.data)
        })
    },
    insertWarehouseLocation(insertWarehouseLocation,callback){
        let url = config.warehouseBaseUrl + "/warehouseLocation/insert"
        axios.post(url,insertWarehouseLocation,{
            headers:{
                token:localStorage.getItem("token")
            }
        }).then(res=>{
            callback(res.data)
        })
    }
}
export default warehouseLocationRequest;